/*************************************************************************
	> File Name: memento.h
	> Author: ma6174
	> Mail: ma6174@163.com 
	> Created Time: 2021年12月02日 星期四 18时54分48秒
 ************************************************************************/

#include<iostream>
#include <string>

//存储箱
class RoleStateMemento
{
public:
	RoleStateMemento() = default;
	RoleStateMemento(int v, int a, int d) : vit(v), atk(a), def(d) {}

	void setVit(int v)
	{
		this->vit = v;
	}

	int getVit()
	{
		return vit;
	}

	void setAtk(int a)
	{
		this->atk = a;
	}

	int getAtk()
	{
		return atk;
	}

	void setDef(int d)
	{
		this->def = d;
	}

	int getDef()
	{
		return def;
	}

private:
	int vit;
	int atk;
	int def;
};

//游戏角色
class GameRole
{
public:
	GameRole()
	{
		initState();
	}

	void setVit(int v)
	{
		vit = v;
	}

	int getVit()
	{
		return vit;
	}

	void setAtk(int a)
	{
		atk = a;
	}

	int getAtk()
	{
		return atk;
	}

	void setDef(int d)
	{
		def = d;
	}

	int getDef()
	{
		return def;
	}

	void display()
	{
		std::cout << "角色当前状态:" << std::endl;
		std::cout << "体力:" << "\t" << vit << std::endl;
		std::cout << "攻击力:" << "\t" << atk << std::endl;
		std::cout << "防御力:" << "\t" << def << std::endl;
		std::cout << std::endl;
	}

	void initState()
	{
		vit = 100;
		atk = 100;
		def = 100;
	}

	void fight()
	{
		vit = 0;
		atk = 0;
		def = 0;
	}

	RoleStateMemento createMemento()
	{
		return RoleStateMemento(vit, atk, def);
	}

	void recovery(RoleStateMemento r)
	{
		vit = r.getVit();
		atk = r.getAtk();
		def = r.getDef();
	}

private:
	int vit;
	int atk;
	int def;
};

//角色状态管理类
class RoleStateCaretaker
{
public:
	RoleStateCaretaker() = default;
	RoleStateCaretaker(RoleStateMemento m) : memento(m) {}

	void setMemento(RoleStateMemento m)
	{
		memento = m;
	}

	RoleStateMemento getMemento()
	{
		return memento;
	}

private:
	RoleStateMemento memento;
};
